package com.yangzheandroid.rxmvp.utils;

import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * 采贝科技有限公司  版权所有(c)
 * Author：yangjilai
 * Time: 2016/8/6 11:46
 * 功能描述:
 */
public class CommonUtils {
    /**
     * 判断是否是十一位手机号码
     */
    public static boolean isMobileNO(String mobiles) {

        Pattern p = Pattern.compile("^((13[0-9])|(15[0-9])|(18[0-9])|(14[0-9])|(17[0-9]))\\d{8}$");

        Matcher m = p.matcher(mobiles);

        return m.matches();

    }

//    /**
//     * 判断是否是十一位手机号码
//     *
//     * @param mobiles
//     * @return
//     */
//    public static boolean isMobileNOLowLevel(String mobiles) {
//
////        Pattern p = Pattern.compile("^()\\d{11}$");
////
////        Matcher m = p.matcher(mobiles);
////
////        return m.matches();
//
//    }

    /**
     * 判断是否是大于等于十一位手机号码
     */
    public static boolean isMobileNOLowLevel(String mobiles) {
        boolean flag = false;
        int length = mobiles.length();
        if (length >= 11) {
            flag = true;
        }
        return flag;
    }

    /**
     * 16位随机数[a-zA-Z0-9]的方法
     */
    public static String getRandomString(int length) {
        String str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
        Random random = new Random();
        StringBuffer sb = new StringBuffer();

        for (int i = 0; i < length; ++i) {
            int number = random.nextInt(62);//[0,62)

            sb.append(str.charAt(number));
        }
        return sb.toString();
    }

}


